package com.rayenterprise.kms.widgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TreeItem;

public abstract class AbstractCustomNode extends TreeItem {
	protected Label text = new Label();
	protected Object obj = new Object();
	
	public void setLblText(String txt) {
		text.setText(txt);
	}

	protected HandlerManager eventBus;
	protected AbstractCustomNode theNode;

	/*
	 * public GenreNode(HandlerManager eventBus) { this.eventBus = eventBus;
	 * this.setWidget(text); initNode(); }
	 */

	public AbstractCustomNode(final Object object, HandlerManager eventBus) {
		this.obj = object;
		this.setUserObject(object);
		this.eventBus = eventBus;
		setCustomLabelText();
		this.setWidget(text);
		theNode = this;
		initNode();

	}
	
	public void initNode() {

		text.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				AbstractCustomEditTab ge;
				if (obj == null)// When creating new Genre
					ge = new AbstractCustomEditTab(eventBus);
				else
					// when edit the genre
					ge = new AbstractCustomEditTab(obj, theNode, eventBus);

				ge.setPopupPosition(getAbsoluteLeft() + 70, getAbsoluteTop());
				ge.show();

			}

		});
	}

	/**
	 * This Method means to be overrided
	 */
	public void setCustomLabelText() {
		// TODO Auto-generated method stub

	}

}
